<template>
  <div class="page-header-index-wide">
    <a-row :gutter="24">
      <a-col :sm="24" :md="12" :xl="4" :style="{ marginBottom: '24px' }">        
          <a-card :loading="loading" :body-style="{ padding: '20px 24px 8px' }" :bordered="false">
            <div class="chart-card-header">
              <div class="meta">
                <span class="chart-card-title">加油站</span>
                <span class="chart-card-action">
                  <slot name="action"></slot>
                </span>
              </div>
              <div class="total"><span id="stationCount">{{station}}</span></div>
            </div>
            <div class="chart-card-content">
              <div class="content-fix">
                <slot></slot>
              </div>
            </div>
            <div class="chart-card-footer">
              <div class="field">
                <slot name="footer"></slot>
              </div>
            </div>
          </a-card>
      </a-col>
      <a-col :sm="24" :md="12" :xl="4" :style="{ marginBottom: '24px' }">
         <a-card :loading="loading" :body-style="{ padding: '20px 24px 8px' }" :bordered="false">
            <div class="chart-card-header">
              <div class="meta">
                <span class="chart-card-title">总金额</span>
                <span class="chart-card-action">
                  <slot name="action"></slot>
                </span>
              </div>
              <div class="total"><span>{{ feesCount }}</span></div>
            </div>
            <div class="chart-card-content">
              <div class="content-fix">
                <slot></slot>
              </div>
            </div>
            <div class="chart-card-footer">
              <div class="field">
                <slot name="footer"></slot>
              </div>
            </div>
          </a-card>
      
      </a-col>
      <a-col :sm="24" :md="12" :xl="4" :style="{ marginBottom: '24px' }">
        <chart-card :loading="loading" title="总油量" v-bind:total="oilCount">          
        </chart-card>
      </a-col>
      <a-col :sm="24" :md="12" :xl="4" :style="{ marginBottom: '24px' }">
        <chart-card :loading="loading" title="加油次数" :total="tradCount">          
        </chart-card>
      </a-col>
      <a-col :sm="24" :md="12" :xl="8" :style="{ marginBottom: '24px' }">
           <a-button class="ant-btn ant-btn-primary" style="width:45%;height:70px;margin: 5px;">蓝色预警<br>48</a-button>
           <a-button class="ant-btn ant-btn-primary" style="width:45%;height:70px;margin: 5px;background-color:#c5c53f;border-color:#c5c53f">黄色预警<br>48</a-button>
           <a-button class="ant-btn ant-btn-primary" style="width:45%;height:70px;margin: 5px;background-color:orange;border-color:orange">橙色预警<br>48</a-button>
           <a-button class="ant-btn ant-btn-primary" style="width:45%;height:70px;margin: 5px;background-color:#f98398;border-color:#f98398">全部预警<br>48</a-button>
      </a-col>
    </a-row>

    
    <a-row :gutter="24">
        <a-col :xs="24" :sm="24" :lg="16">
          <div class="chart-wrapper">
                <bar-chart />
          </div>
      </a-col>
      <a-col :xs="24" :sm="24" :lg="8">
              <live />
      </a-col>  
    </a-row>

    <a-row :gutter="32">
      <a-col :xs="24" :sm="24" :lg="8">
        <div class="chart-wrapper">
           <pie-chart :pie="pie1"/>
        </div>
      </a-col>
      <a-col :xs="24" :sm="24" :lg="8">
        <div class="chart-wrapper">
          <pie-chart :pie="pie2" />
        </div>
      </a-col>
      <a-col :xs="24" :sm="24" :lg="8">
        <div class="chart-wrapper">
          <pie-chart :pie="pie3" />
        </div>
      </a-col>
    </a-row>

  
  </div>
</template>

<script>
  import ChartCard from '@/components/ChartCard'
  import ACol from "ant-design-vue/es/grid/Col"
  import ATooltip from "ant-design-vue/es/tooltip/Tooltip"
  import MiniArea from '@/components/chart/MiniArea'
  import MiniBar from '@/components/chart/MiniBar'
  import MiniProgress from '@/components/chart/MiniProgress'
  import RankList from '@/components/chart/RankList'
  import Bar from '@/components/chart/Bar'
  import LineChartMultid from '@/components/chart/LineChartMultid'
  import HeadInfo from '@/components/tools/HeadInfo.vue'
  import BarChart from './components/BarChart'
  import live from './components/live.vue'
  import PieChart from './components/PieChart'
  import Trend from '@/components/Trend'
  import { getLoginfo,getVisitInfo } from '@/api/api'

  
  export default {
    name: "IndexChart",
    components: {
      ATooltip,
      ACol,
      ChartCard,
      MiniArea,
      MiniBar,
      MiniProgress,
      RankList,
      Bar,
      Trend,
      LineChartMultid,
      HeadInfo,
      BarChart,
      live,
      PieChart
    },
    data() {
      return {
        loading: true,
        center: null,
        rankList,
        barData,
        loginfo:{},
        visitFields:['ip','visit'],
        visitInfo:[],
        indicator: <a-icon type="loading" style="font-size: 24px" spin />,        
        station:"1",
        feesCount:"2",
        oilCount:"3",
        tradCount:"5",
        total:"test"        
       }
    },
    mounted(){ 
          this.pie1={
            className:"石化能源占比",
            data:[
                    {value: 50, name: '汽油'},
                    {value: 50, name: '柴油'},
                ]
          };
          this.pie2={
            className:"汽油销售占比",
            data:[
                    {value: 70, name: '92#'},
                    {value: 30, name: '95#'},
                ]
          };
          this.pie3={
            className:"柴油销售占比",
            data:[
                    {value: 90, name: '0#'},
                    {value: 10, name: '-10#'},
                ]
          };
          
          setTimeout(() => {
            this.stationCount=10;
            this.feesCount=20;
            this.oilCount=30;
            this.tradCount=50;
            window.console.log("after 5 min");
          }, 5000)
         
      
        
    },
    created() {
      setTimeout(() => {
        this.loading = !this.loading
        this.yaochuan="very cool"
      }, 1000)
      this.initLogInfo();  
      getIndexData();     
    },
    methods: {
      initLogInfo () {
        getLoginfo(null).then((res)=>{
          if(res.success){
            Object.keys(res.result).forEach(key=>{
              res.result[key] =res.result[key]+""
            })
            this.loginfo = res.result;
          }
        })
        getVisitInfo().then(res=>{
          if(res.success){
             this.visitInfo = res.result;
           }
         })
      },
      getIndexData(){
        this.$http.get('/welcome/data')
          .then(res => {
            window.console.log(res.result.feesCount+res.result.stationCount);
            this.stationCount=res.result.stationCount;
            this.feesCount=res.result.feesCount;
            this.oilCount=res.result.oilCount;
            this.tradCount=res.result.tradCount;
          })
      }
    }
  }
</script>

<style lang="less" scoped>
  .circle-cust{
    position: relative;
    top: 28px;
    left: -100%;
  }
  .extra-wrapper {
    line-height: 55px;
    padding-right: 24px;

    .extra-item {
      display: inline-block;
      margin-right: 24px;

      a {
        margin-left: 24px;
      }
    }
  }

  /* 首页访问量统计 */
  .head-info {
    position: relative;
    text-align: left;
    padding: 0 32px 0 0;
    min-width: 125px;

    &.center {
      text-align: center;
      padding: 0 32px;
    }

    span {
      color: rgba(0, 0, 0, .45);
      display: inline-block;
      font-size: .95rem;
      line-height: 42px;
      margin-bottom: 4px;
    }
    p {
      line-height: 42px;
      margin: 0;
      a {
        font-weight: 600;
        font-size: 1rem;
      }
    }
  }
  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
  @media (max-width:1024px) {
  .chart-wrapper {
    padding: 8px;
  }
  
}
.chart-card-header {
    position: relative;
    overflow: hidden;
    width: 100%;

    .meta {
      position: relative;
      overflow: hidden;
      width: 100%;
      color: rgba(0, 0, 0, .45);
      font-size: 14px;
      line-height: 22px;
    }
  }

  .chart-card-action {
    cursor: pointer;
    position: absolute;
    top: 0;
    right: 0;
  }

  .chart-card-footer {
    border-top: 1px solid #e8e8e8;
    padding-top: 9px;
    margin-top: 8px;

    > * {
      position: relative;
    }

    .field {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      margin: 0;
    }
  }

  .chart-card-content {
    margin-bottom: 12px;
    position: relative;
    height: 46px;
    width: 100%;

    .content-fix {
      position: absolute;
      left: 0;
      bottom: 0;
      width: 100%;
    }
  }

  .total {
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: break-all;
    white-space: nowrap;
    color: #000;
    margin-top: 4px;
    margin-bottom: 0;
    font-size: 30px;
    line-height: 38px;
    height: 38px;
  }
</style>